package com.runner.input;

import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.runner.screen.GameScreen;
import com.runner.utility.Constants;

public class InputHandler implements GestureListener, Constants {
	private GameScreen screen;
	private boolean touched;

	public InputHandler(GameScreen screen) {
		this.screen = screen;
	}

	@Override
	public boolean touchDown(float x, float y, int pointer, int button) {
		// hero climbs the wall
		if (!screen.isPause()) {
			if (!screen.isRestart()) {
				screen.touchDown(x, y, false);
			} else {
				screen.touchDown(x, y, true);
			}
		}
		return false;
	}

	@Override
	public boolean fling(float velocityX, float velocityY, int button) {
		// hero jumps to other side
		if (touched && !screen.isPause() && !screen.isRestart()) {
			Vector2 dir = new Vector2(velocityX, velocityY);
			dir.nor();
			if (dir.x > Math.sqrt(2) / 2) { // swipe right
			}
			if (dir.y > Math.sqrt(2) / 2) { // swipe down
			}
			if (dir.x < -Math.sqrt(2) / 2) { // swipe left
			}
			if (dir.y < -Math.sqrt(2) / 2) { // swipe up
			}
			touched = false;
			screen.fling(velocityX, velocityY);
		}
		return false;
	}

	@Override
	public boolean panStop(float x, float y, int pointer, int button) {
		if (!screen.isPause() && !screen.isRestart()) {
			screen.tap(x, y);
		}
		return false;
	}

	@Override
	public boolean tap(float x, float y, int count, int button) {
		if (!screen.isPause() && !screen.isRestart()) {
			screen.tap(x, y);
		}
		return false;
	}

	@Override
	public boolean longPress(float x, float y) {
		return false;
	}

	@Override
	public boolean pan(float x, float y, float deltaX, float deltaY) {
		return false;
	}

	@Override
	public boolean zoom(float initialDistance, float distance) {
		return false;
	}

	@Override
	public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
		return false;
	}

}